package com.cooper.controllers.buyer;


import org.springframework.beans.factory.annotation.Autowired;

import com.cooper.constants.ResourceConstants;
import com.cooper.controllers.Controller;
import com.cooper.controllers.LoginRequired;
import com.cooper.entity.UserInfo;
import com.cooper.favorite.FavoriteService;
import com.cooper.pagination.PageInfo;
import com.cooper.util.Controllers;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

@LoginRequired
public class FavoriteController extends Controller {

	@Autowired
	FavoriteService favoriteService;
	@Get @Post
	public String execute(Invocation inv,@Param("origin") String origin,PageInfo pageInfo) throws Exception{
		UserInfo user = Controllers.getUserInfo(inv);
		inv.addModel("user",user);
		if(ResourceConstants.LikeOrigin.SHOP_LIKE.equals(origin)){
			pageInfo.setRowCount(favoriteService.queryFavoriteDesignerCount(user.getId()));
			inv.addModel("dataList", favoriteService.queryFavoriteShopList(user.getId(), pageInfo));
			inv.addModel("origin", ResourceConstants.LikeOrigin.SHOP_LIKE);
		}else{
			pageInfo.setRowCount(favoriteService.queryFavoriteItemInfoCount(user.getId()));
			inv.addModel("dataList", favoriteService.queryFavoriteItemInfoList(user.getId(), pageInfo));
			inv.addModel("origin", ResourceConstants.LikeOrigin.ITEM_LIKE);
		}
		inv.addModel("pageInfo",pageInfo);
		return "BuyerFavorite";
	}
	
}
